package reflect;

import java.util.Scanner;

/**
 * 使用类对象实例化
 */
public class ReflectDemo2 {
    public static void main(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException {
        Person p  = new Person();
        System.out.println(p);

        /*
            java.util.ArrayList     java.util.HashMap
            reflect.Person          java.util.Date
         */
//        Class cls = Class.forName("reflect.Person");
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入一个类名:");
        String className =scanner.nextLine();
        Class cls = Class.forName(className);
        //newInstance()方法会调用类对象所表示的类的【公开的无参构造器】实例化
        Object obj = cls.newInstance();//new Person();
        System.out.println(obj);
    }


}
